import {HOME_ROUTE} from "@/router/routes/home/home.js";

// user store
// const userStore = useUserStore()

// *******
// * 登录 *
// *******
export function login(loginBtnLoading, loginBtnDisable, loginHandler, router, route) {
    // 按钮状态
    loginBtnLoading.value = true
    loginBtnDisable.value = true
    return loginHandler().then(
        data => {
            // 结束加载状态
            loginBtnLoading.value = false
            loginBtnDisable.value = false
            // 登录成功
            if (data) {
                const toRouteName = route.query.toRouteName
                if (toRouteName !== null && toRouteName !== undefined && toRouteName.length >= 0) {
                    // 跳转到原来要前往的页面
                    router.replace({name: toRouteName})
                } else {
                    router.replace({name: HOME_ROUTE})
                }

            }
        },
        () => {
            // 结束加载状态
            loginBtnLoading.value = false
            loginBtnDisable.value = false
        }
    )
}